#!/bin/sh

ETH_MAC_LOCATION="/sys/bus/i2c/drivers/at24/2-0050/eeprom"
ETH_MAC_OFFSET="0xfa"
ETH_MAC_LENGTH=6
DUMP_FORMAT="$ETH_MAC_LENGTH/1 \"%02X\" \"\\n\""

show_help()
{                        
        echo -e \
"Usage:\n\
 $0\n\n\
Check the EEPROM has MAC address data.\n"
} 


mac_test()
{
	ETH_MAC=$(hexdump -s $ETH_MAC_OFFSET -n $ETH_MAC_LENGTH \
		-e "$DUMP_FORMAT" $ETH_MAC_LOCATION)
	echo Ethernet MAC address: $ETH_MAC

	if [ $ETH_MAC == "FFFFFFFFFFFF" ] || [ $ETH_MAC == "000000000000" ]; then
		echo FAIL
	else
		echo PASS
	fi
}


# A POSIX variable
OPTIND=1         # Reset in case getopts has been used previously in the shell.

while getopts "h?" opt; do
        case "$opt" in
        h|\?)
                show_help
                exit 0
                ;;
        esac
done

shift $((OPTIND-1))

mac_test
